//
//  MainViewController.m
//  51易借
//
//  Created by 张睿 on 2017/8/21.
//  Copyright © 2017年 张睿. All rights reserved.
//

#import "MainViewController.h"
#import "HomeViewController.h"
#import "RepaymentViewController.h"
#import "MyselfViewController.h"
#import "OrangeNavController.h"

@interface MainViewController ()

@end

#define kUITabBarHeight 49
#define kTabBarItemCount3

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupUI];
//    [self loadData];
}

//- (void)loadData{
//    
//    [[NetworkTool shareManager] POST:@"user/login.json" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *  _Nullable responseObject) {
//        
//        NSString * code = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
//        
//        if ([code isEqualToString:@"0"]) {
//            
//            NSDictionary * data = responseObject[@"data"];
//            
//            DEF_SET_OBJECT(data[@"registerProtocol"],@"registerProtocol");
//            DEF_SET_OBJECT(data[@"helpCenter"],@"helpCenter");
//            DEF_SET_OBJECT(data[@"operatorAuthProtocol"],@"operatorAuthProtocol");
//            DEF_SET_OBJECT(data[@"loanProtocol"],@"loanProtocol");
//            DEF_SET_OBJECT(data[@"platformServiceProtocol"],@"platformServiceProtocol");
//            DEF_SET_OBJECT(data[@"authDeductDelegate"],@"authDeductDelegate");
//            DEF_SET_OBJECT(data[@"aboutCompany"],@"aboutCompany");
//        }
//        
//        
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        
//        NSLog(@"==%@",error);
//        
//    }];
//}


-(void)setupUI {
    
    [[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];
    
    [UITabBar appearance].translucent = NO;
    
    HomeViewController * homeVC = [HomeViewController new];
    homeVC.title = @"借款";
    
    RepaymentViewController * repaymentVC = [RepaymentViewController new];
    repaymentVC.title = @"还款";
    
    MyselfViewController * myVC = [MyselfViewController new];
    myVC.title = @"我的";
//
    OrangeNavController * homeNav = [[OrangeNavController alloc] initWithRootViewController:homeVC];
    
    OrangeNavController * repaymentNav = [[OrangeNavController alloc] initWithRootViewController:repaymentVC];
    
    OrangeNavController * myselfNav = [[OrangeNavController alloc] initWithRootViewController:myVC];

    
    
    //设置控制器图片(使用imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal,不被系统渲染成蓝色)
    homeNav.tabBarItem.image = [[UIImage imageNamed:@"底部借款-灰"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    homeNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"底部借款-亮"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    repaymentNav.tabBarItem.image = [[UIImage imageNamed:@"底部还款灰"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    repaymentNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"底部还款亮"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    myselfNav.tabBarItem.image = [[UIImage imageNamed:@"底部我的灰"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    myselfNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"底部我的亮"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    
    //改变tabbarController 文字选中颜色(默认渲染为蓝色)
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor grayColor]} forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:ColorWithRGB(0xff7907)} forState:UIControlStateSelected];
    
    //创建一个数组包含四个导航栏控制器
    NSArray *vcArry = [NSArray arrayWithObjects:homeNav,repaymentNav,myselfNav,nil];
    
    //将数组传给UITabBarController
    self.viewControllers = vcArry;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
